﻿using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using SaiLing.Domain;
using SaiLing.Repository;
using SaiLing.SingleSignOn.Repository.Mapping.System;

namespace SaiLing.SingleSignOn.Repository
{
    public class ProjectDbContext : BaseDbContext
    {
        public ProjectDbContext()
        {
        }
        public async Task<bool> SaveEntitiesAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            var result = await SaveChangesAsync(cancellationToken);

            return result > 0;
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlServer(ProjectEntitySetting.Instance.ConnectionString);
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            builder.ApplyConfiguration(new AccountMapping());
            builder.ApplyConfiguration(new ApplicationMapping());
            builder.ApplyConfiguration(new ModuleMapping());
            builder.ApplyConfiguration(new ModuleActionMapping());
            builder.ApplyConfiguration(new OperationLogMapping());
            builder.ApplyConfiguration(new OrganizationMapping());
            builder.ApplyConfiguration(new PositionMapping());
            builder.ApplyConfiguration(new OrganizationMenuAuthorityMapping());
            builder.ApplyConfiguration(new UserPositionMapping());
        }


    }
}
